package logic

import (
	"context"
	"furni-link/furnirpc/furnirpcclient"

	"furni-link/api/internal/svc"
	"furni-link/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type FurnAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFurnAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FurnAddLogic {
	return &FurnAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FurnAddLogic) FurnAdd(req *types.FurnAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.FurnRpc.FurnAdd(l.ctx, &furnirpcclient.FurnAddRequest{
		FurnName: req.FurnName,
		Price:    float32(req.Price),
		Num:      int64(req.Num),
		ClassId:  int64(req.ClassId),
		BrandId:  int64(req.BrandId),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "添加成功",
		Data:    add,
		Code:    200,
	}, nil
}
